<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('进度填报列表')" />
    <style>
        .badge-success,.badge-primary{
            background-color: #1ab394;
        }
        .badge-warning{
            background-color: #b31925;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>任务名称：</p>
                                <input type="text" name="taskName"/>
                            </li>
                            <li>
                                <p>任务类型：</p>
                                <select name="taskType" th:with="type=${@dict.getType('')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <li>
                                <p>任务期号：</p>
                                <input type="text" name="taskNum"/>
                            </li>
                            <li>
                                <p>项目名称：</p>
                                <input type="text" name="projectName"/>
                            </li>
                            <li>
                                <p>任务状态：</p>
                                <select name="taskStatus">
                                    <option value="">所有</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">-->

                <!--<a class="btn btn-primary single disabled" onclick="edit()" shiro:hasPermission="linkong:fill:edit">-->
                    <!--<i class="fa fa-edit"></i> 填报-->
                <!--</a>-->
                <!--<a class="btn btn-danger single disabled" onclick="applySubmit()" shiro:hasPermission="linkong:fill:remove">-->
                    <!--<i class="fa fa-paper-plane"></i> 提交审核-->
                <!--</a>-->

                <!--<a class="btn btn-success btn-xs single disabled" onclick="apply_fun()"-->
                   <!--shiro:hasPermission="system:info:applySubmit">-->
                    <!--<i class="fa fa-edit"></i> 审核-->
                <!--</a>-->

            <!--</div>-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('linkong:fill:edit')}]];
        var removeFlag = [[${@permission.hasPermi('linkong:fill:remove')}]];
        var applySubmitFlag = [[${@permission.hasPermi('linkong:fill:applySubmit')}]];
        var prefix = ctx + "linkong/fill";
        var types = [[${@dict.getType('task_type')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                updateUrl: prefix + "/edit/{id}",
                applyUrl: prefix + "/apply/{id}",
                detailUrl: prefix + "/detail/{id}",
                modalName: "进度填报",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'taskId', 
                    title : '主键',
                    visible: false
                },

                {
                    field : 'taskName',
                    align: 'center',
                    title : '任务名称'
                },
                {
                    field : 'taskNum',
                    align: 'center',
                    title : '任务期号'
                },
                {
                    field : 'taskType',
                    align: 'center',
                    title : '任务类型',
                    formatter:function(value,row){
                        return $.table.selectDictLabel(types, value);
                    }
                },
                {
                    field : 'reportingCycle',
                    align: 'center',
                    title : '上报周期',
                    formatter:function (value) {
                        if(value=='0'){
                            return '临时';
                        }
                        if(value=='1'){
                            return '月报';
                        }
                        if(value=='2'){
                            return '季报';
                        }
                    }
                },

                {
                    field : 'projectCode',
                    align: 'center',
                    title : '项目编码'
                },
                {
                    field : 'projectName',
                    align: 'center',
                    title : '项目名称'
                },

                {
                    field : 'companyName',
                    align: 'center',
                    title : '负责企业'
                },
                {
                    field : 'createTime',
                    align: 'center',
                    title : '下发日期'
                },
                    {
                        field : 'fillStatus',
                        align: 'center',
                        title : '填报状态',
                        formatter:function (value) {
                            var result = "";
                            if (value == 1) {
                                result = '待填报';
                            } else if (value == 0) {
                                result = '已填报';
                            }
                            return result;
                        }
                    },
                    //任务状态（0：待上报，1：已上报，2已通过，3：已退回）
                {
                    field : 'taskStatus',
                    align: 'center',
                    title : '任务状态',
                    formatter: function (value, row, index) {
                        var result = "";
                        if (value == 0) {
                            // result = '<span class="badge badge-danger">待上报</span>';
                            result = '待上报';
                        } else if (value == 1) {
                            // result = '<span class="badge badge-success">已上报</span>';
                            result = '已上报';
                        } else if (value == 2) {
                            // result = '<span class="badge badge-primary">已通过</span>';
                            result = '已通过';
                        }else if (value == 3) {
                            // result = '<span class="badge badge-warning">已退回</span>';
                            result = '已退回';
                        }
                        return result;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="toDetail(\'' + row.taskId + '\')"><i class="fa fa-search"></i>查看</a> ');
                        if(row.taskStatus == 3){
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '"href="javascript:void(0)" onclick="edit2(\'' + row.taskStatus + '\',\'' + row.taskId + '\')"><i class="fa fa-edit"></i>补充</a> ');
                        }else{
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '"href="javascript:void(0)" onclick="edit(\'' + row.fillStatus + '\',\'' + row.taskId + '\')"><i class="fa fa-edit"></i>填报</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '"href="javascript:void(0)" onclick="applySubmit(\'' + row.fillStatus + '\',\'' + row.taskId + '\',\'' + row.taskStatus + '\')"><i class="fa fa-paper-plane"></i>提交审核</a> ');

                        actions.push('<a class="btn btn-success btn-xs ' + applySubmitFlag + '" href="javascript:void(0)" onclick="apply_fun(\'' + row.taskId + '\',\'' + row.taskStatus + '\' )"><i class="fa fa-search"></i>审核</a> ');
                        return actions.join('');
                    }
                }
                ]
            };
            $.table.init(options);
        });

        function edit(fillStatus ,rowId){
            // // 获取选中的对象
            // var rows = $.map($('#' + $.table._option.id).bootstrapTable('getSelections'), function (row) {
            //     return row;
            // });
            // var fillStatus = rows[0].fillStatus;
            if(fillStatus != 1){
              return  $.modal.alertError("该任务非待填报状态");
            }
            // var task_id = rows[0].taskId;
            var url = $.table._option.updateUrl.replace("{id}", rowId);
            $.modal.open( "进度填报", url,1200,800);
        }

        function edit2(taskStatus ,rowId){
            // // 获取选中的对象
            // var rows = $.map($('#' + $.table._option.id).bootstrapTable('getSelections'), function (row) {
            //     return row;
            // });
            // var fillStatus = rows[0].fillStatus;
            if(taskStatus != 3){
                return  $.modal.alertError("该任务非待补充状态");
            }
            // var task_id = rows[0].taskId;
            var url = $.table._option.updateUrl.replace("{id}", rowId);
            $.modal.open( "补充填报", url,1200,800);
        }
        // 上报提交审核
        function applySubmit(fillStatus ,rowId,taskStatus){
            // var rows = $.map($('#' + $.table._option.id).bootstrapTable('getSelections'), function (row) {
            //     return row;
            // });

            // var fillStatus = rows[0].fillStatus;
            // var taskStatus = rows[0].taskStatus;
            // var task_id = rows[0].taskId;
            if(fillStatus == 1){
                return  $.modal.alertError("请填报后再提交审核");
            }
            if(fillStatus == 0 && (taskStatus ==0 || taskStatus == 3)){
                $.modal.confirm("确认要提交审核选中的数据吗?", function() {
                    var url = prefix + "/edit";
                    var data = { "taskId": rowId , taskStatus:"1"};
                    $.operate.submit(url, "post", "json", data);
                });
            }else{
                return  $.modal.alertError("该任务非上报审核状态");
            }
        }

        // 项目办-- 审核
        function apply_fun(rowId,taskStatus) {
            // 获取选中的对象
            // var rows = $.map($('#' + $.table._option.id).bootstrapTable('getSelections'), function (row) {
            //     return row;
            // });
            if (taskStatus != 1) {
                $.modal.alertError("抱歉，该数据并非未审核状态");
                return false;
            }
            // var task_id = rows[0].taskId;
            var url = $.common.isEmpty(rowId) ? $.table._option.applyUrl : $.table._option.applyUrl.replace("{id}", rowId);
            layer.open({
                type: 2,
                shade: 0.3,
                title: "审核操作",
                fix: false,
                area: [1200 + 'px', 800 + 'px'],
                content: url,
                cancel: function () {
                    return true;
                }
            });
        }
        // 查看
        function toDetail(task_id) {
                var options = {
                    url: $.common.isEmpty(task_id) ? $.table._option.detailUrl : $.table._option.detailUrl.replace("{id}", task_id),
                    title: $.table._option.modalName + "详情",
                    width:1200,
                    height:800,
                    btn :[ '<i class="fa fa-close"></i> 关闭'],
                    callBack:function(index){
                            layer.close(index);
                    }
                }
                $.modal.openOptions(options);

        }
    </script>
</body>
</html>